import threading, requests, queue

class DafsThread(threading.Thread):
    q = None
    method = None
    url = None
    mask_symbol = None
    counter = None

    def __init__(self, q, result, url, method, mask_symbol, counter):
        super().__init__()
        self.q = q
        self.method = method
        self.url = url
        self.mask_symbol = mask_symbol
        self.result = result
        self.counter = counter

    def run(self):
        sess = requests.Session()
        while True:
            try:
                word = self.q.get()

                self.counter.up()

                url = self.url.replace(self.mask_symbol, word)
                resp = sess.head(url) \
                        if self.method.lower() == 'head' \
                        else sess.head(url)
                if resp.status_code != 404:
                    self.result.put(url)

            except queue.Empty:
                break
            except BaseException as e:
                print(url + " " + str(e))
            finally:
                self.q.task_done()
